package electron.karakum.inheritanceModifiers

import arrow.core.raise.nullable
import io.github.sgrishchenko.karakum.extension.InheritanceModifierContext
import io.github.sgrishchenko.karakum.util.getParentOrNull
import typescript.Node
import typescript.isClassDeclaration
import typescript.isIdentifier
import typescript.isMethodDeclaration

fun modifyMethodInheritance(node: Node, context: InheritanceModifierContext) = nullable {
    nullable {
        ensure(isMethodDeclaration(node))

        val name = node.name
        ensure(isIdentifier(name))

        nullable {
            ensure(
                name.text == "blur"
                        || name.text == "center"
                        || name.text == "close"
                        || name.text == "closeFilePreview"
                        || name.text == "destroy"
                        || name.text == "flashFrame"
                        || name.text == "focus"
                        || name.text == "getAccentColor"
                        || name.text == "getBackgroundColor"
                        || name.text == "getBounds"
                        || name.text == "getChildWindows"
                        || name.text == "getContentBounds"
                        || name.text == "getContentSize"
                        || name.text == "getMaximumSize"
                        || name.text == "getMediaSourceId"
                        || name.text == "getMinimumSize"
                        || name.text == "getNativeWindowHandle"
                        || name.text == "getNormalBounds"
                        || name.text == "getOpacity"
                        || name.text == "getParentWindow"
                        || name.text == "getPosition"
                        || name.text == "getRepresentedFilename"
                        || name.text == "getSize"
                        || name.text == "getTitle"
                        || name.text == "getWindowButtonPosition"
                        || name.text == "hasShadow"
                        || name.text == "hide"
                        || name.text == "hookWindowMessage"
                        || name.text == "invalidateShadow"
                        || name.text == "isAlwaysOnTop"
                        || name.text == "isClosable"
                        || name.text == "isContentProtected"
                        || name.text == "isDestroyed"
                        || name.text == "isDocumentEdited"
                        || name.text == "isEnabled"
                        || name.text == "isFocusable"
                        || name.text == "isFocused"
                        || name.text == "isFullScreen"
                        || name.text == "isFullScreenable"
                        || name.text == "isHiddenInMissionControl"
                        || name.text == "isKiosk"
                        || name.text == "isMaximizable"
                        || name.text == "isMaximized"
                        || name.text == "isMenuBarAutoHide"
                        || name.text == "isMenuBarVisible"
                        || name.text == "isMinimizable"
                        || name.text == "isMinimized"
                        || name.text == "isModal"
                        || name.text == "isMovable"
                        || name.text == "isNormal"
                        || name.text == "isResizable"
                        || name.text == "isSimpleFullScreen"
                        || name.text == "isSnapped"
                        || name.text == "isTabletMode"
                        || name.text == "isVisible"
                        || name.text == "isVisibleOnAllWorkspaces"
                        || name.text == "isWindowMessageHooked"
                        || name.text == "maximize"
                        || name.text == "mergeAllWindows"
                        || name.text == "minimize"
                        || name.text == "moveAbove"
                        || name.text == "moveTabToNewWindow"
                        || name.text == "moveTop"
                        || name.text == "previewFile"
                        || name.text == "removeMenu"
                        || name.text == "restore"
                        || name.text == "selectNextTab"
                        || name.text == "selectPreviousTab"
                        || name.text == "setAccentColor"
                        || name.text == "setAppDetails"
                        || name.text == "setAspectRatio"
                        || name.text == "setAutoHideCursor"
                        || name.text == "setAutoHideMenuBar"
                        || name.text == "setBackgroundColor"
                        || name.text == "setBounds"
                        || name.text == "setClosable"
                        || name.text == "setContentBounds"
                        || name.text == "setContentProtection"
                        || name.text == "setContentSize"
                        || name.text == "setDocumentEdited"
                        || name.text == "setEnabled"
                        || name.text == "setFocusable"
                        || name.text == "setFullScreen"
                        || name.text == "setFullScreenable"
                        || name.text == "setHasShadow"
                        || name.text == "setHiddenInMissionControl"
                        || name.text == "setIcon"
                        || name.text == "setIcon"
                        || name.text == "setIgnoreMouseEvents"
                        || name.text == "setKiosk"
                        || name.text == "setMaximizable"
                        || name.text == "setMaximumSize"
                        || name.text == "setMenu"
                        || name.text == "setMenuBarVisibility"
                        || name.text == "setMinimizable"
                        || name.text == "setMinimumSize"
                        || name.text == "setMovable"
                        || name.text == "setOpacity"
                        || name.text == "setOverlayIcon"
                        || name.text == "setPosition"
                        || name.text == "setProgressBar"
                        || name.text == "setRepresentedFilename"
                        || name.text == "setResizable"
                        || name.text == "setShape"
                        || name.text == "setSheetOffset"
                        || name.text == "setSimpleFullScreen"
                        || name.text == "setSize"
                        || name.text == "setSkipTaskbar"
                        || name.text == "setThumbarButtons"
                        || name.text == "setThumbnailClip"
                        || name.text == "setThumbnailToolTip"
                        || name.text == "setTitle"
                        || name.text == "setTitleBarOverlay"
                        || name.text == "setTouchBar"
                        || name.text == "setVisibleOnAllWorkspaces"
                        || name.text == "setWindowButtonPosition"
                        || name.text == "setWindowButtonVisibility"
                        || name.text == "show"
                        || name.text == "showAllTabs"
                        || name.text == "showInactive"
                        || name.text == "toggleTabBar"
                        || name.text == "unhookAllWindowMessages"
                        || name.text == "unhookWindowMessage"
                        || name.text == "unmaximize"
            )

            val classNode = ensureNotNull(node.getParentOrNull())
            ensure(isClassDeclaration(classNode))
            ensure(classNode.name?.text == "BaseWindow")

            "open"
        }  ?: nullable {
            ensure(
                name.text == "blur"
                        || name.text == "center"
                        || name.text == "close"
                        || name.text == "closeFilePreview"
                        || name.text == "destroy"
                        || name.text == "flashFrame"
                        || name.text == "focus"
                        || name.text == "getAccentColor"
                        || name.text == "getBackgroundColor"
                        || name.text == "getBounds"
                        || name.text == "getChildWindows"
                        || name.text == "getContentBounds"
                        || name.text == "getContentSize"
                        || name.text == "getMaximumSize"
                        || name.text == "getMediaSourceId"
                        || name.text == "getMinimumSize"
                        || name.text == "getNativeWindowHandle"
                        || name.text == "getNormalBounds"
                        || name.text == "getOpacity"
                        || name.text == "getParentWindow"
                        || name.text == "getPosition"
                        || name.text == "getRepresentedFilename"
                        || name.text == "getSize"
                        || name.text == "getTitle"
                        || name.text == "getWindowButtonPosition"
                        || name.text == "hasShadow"
                        || name.text == "hide"
                        || name.text == "hookWindowMessage"
                        || name.text == "invalidateShadow"
                        || name.text == "isAlwaysOnTop"
                        || name.text == "isClosable"
                        || name.text == "isContentProtected"
                        || name.text == "isDestroyed"
                        || name.text == "isDocumentEdited"
                        || name.text == "isEnabled"
                        || name.text == "isFocusable"
                        || name.text == "isFocused"
                        || name.text == "isFullScreen"
                        || name.text == "isFullScreenable"
                        || name.text == "isHiddenInMissionControl"
                        || name.text == "isKiosk"
                        || name.text == "isMaximizable"
                        || name.text == "isMaximized"
                        || name.text == "isMenuBarAutoHide"
                        || name.text == "isMenuBarVisible"
                        || name.text == "isMinimizable"
                        || name.text == "isMinimized"
                        || name.text == "isModal"
                        || name.text == "isMovable"
                        || name.text == "isNormal"
                        || name.text == "isResizable"
                        || name.text == "isSimpleFullScreen"
                        || name.text == "isSnapped"
                        || name.text == "isTabletMode"
                        || name.text == "isVisible"
                        || name.text == "isVisibleOnAllWorkspaces"
                        || name.text == "isWindowMessageHooked"
                        || name.text == "maximize"
                        || name.text == "mergeAllWindows"
                        || name.text == "minimize"
                        || name.text == "moveAbove"
                        || name.text == "moveTabToNewWindow"
                        || name.text == "moveTop"
                        || name.text == "previewFile"
                        || name.text == "removeMenu"
                        || name.text == "restore"
                        || name.text == "selectNextTab"
                        || name.text == "selectPreviousTab"
                        || name.text == "setAccentColor"
                        || name.text == "setAppDetails"
                        || name.text == "setAspectRatio"
                        || name.text == "setAutoHideCursor"
                        || name.text == "setAutoHideMenuBar"
                        || name.text == "setBackgroundColor"
                        || name.text == "setBounds"
                        || name.text == "setClosable"
                        || name.text == "setContentBounds"
                        || name.text == "setContentProtection"
                        || name.text == "setContentSize"
                        || name.text == "setDocumentEdited"
                        || name.text == "setEnabled"
                        || name.text == "setFocusable"
                        || name.text == "setFullScreen"
                        || name.text == "setFullScreenable"
                        || name.text == "setHasShadow"
                        || name.text == "setHiddenInMissionControl"
                        || name.text == "setIcon"
                        || name.text == "setIcon"
                        || name.text == "setIgnoreMouseEvents"
                        || name.text == "setKiosk"
                        || name.text == "setMaximizable"
                        || name.text == "setMaximumSize"
                        || name.text == "setMenu"
                        || name.text == "setMenuBarVisibility"
                        || name.text == "setMinimizable"
                        || name.text == "setMinimumSize"
                        || name.text == "setMovable"
                        || name.text == "setOpacity"
                        || name.text == "setOverlayIcon"
                        || name.text == "setPosition"
                        || name.text == "setProgressBar"
                        || name.text == "setRepresentedFilename"
                        || name.text == "setResizable"
                        || name.text == "setShape"
                        || name.text == "setSheetOffset"
                        || name.text == "setSimpleFullScreen"
                        || name.text == "setSize"
                        || name.text == "setSkipTaskbar"
                        || name.text == "setThumbarButtons"
                        || name.text == "setThumbnailClip"
                        || name.text == "setThumbnailToolTip"
                        || name.text == "setTitle"
                        || name.text == "setTitleBarOverlay"
                        || name.text == "setTouchBar"
                        || name.text == "setVisibleOnAllWorkspaces"
                        || name.text == "setWindowButtonPosition"
                        || name.text == "setWindowButtonVisibility"
                        || name.text == "show"
                        || name.text == "showAllTabs"
                        || name.text == "showInactive"
                        || name.text == "toggleTabBar"
                        || name.text == "unhookAllWindowMessages"
                        || name.text == "unhookWindowMessage"
                        || name.text == "unmaximize"
            )

            val classNode = ensureNotNull(node.getParentOrNull())
            ensure(isClassDeclaration(classNode))
            ensure(classNode.name?.text == "BrowserWindow")

            "override"
        }
    }
}
